package club.itstudio.IContainer.container;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;

@Service
public class ContainerNetwork {

    ExecContainerCommand execContainerCommand;

    // create network
    public void Create(String driver, String subnet, String networkName) throws IOException {
        StringBuilder sb = new StringBuilder();
        sb.append("network create ");
        sb.append("--driver ").append(driver).append(' ');
        sb.append("--subnet ").append(subnet).append(' ');
        sb.append(networkName);
        execContainerCommand.Exec(sb.toString());
    }

    // remove network
    public void Remove(String networkName) throws IOException {
        StringBuilder sb = new StringBuilder();
        sb.append("network remove ");
        sb.append(networkName);
        execContainerCommand.Exec(sb.toString());
    }

    @Autowired
    public void setExecContainerCommand(ExecContainerCommand execContainerCommand) {
        this.execContainerCommand = execContainerCommand;
    }
}
